<?php
##include_once dirname(__FILE__).'/../_config.php';

/**
 * 在这里定义本目录下的特定变量
 */

function make_menu_ul($menu_tree, $menu_expand){
	global $__s_manager_self, $__l;
	if(!isset(Statics::$access_arr) || !is_array(Statics::$access_arr)){
		die('缺少配置文件');
	}
	
	if(empty($menu_tree))return '';
	$_tmp_access = @array_keys(Statics::$access_arr);
	$mapping_arr = Statics::$super_agency_mapping_arr[$__s_manager_self['super']];
	$menu_arr = array();
	foreach($menu_tree as $menu){
		if(!empty($__s_manager_self['agency_id']) && !empty($__s_manager_self['agency_role']) && $__s_manager_self['role'] != $__s_manager_self['agency_role']){
			if(
				empty($menu['agency']) ||
				(!in_array($menu['agency'], $mapping_arr))
			)continue;
		}
		
		if($menu['path'] == '#' || in_array($menu['path'], $_tmp_access)){
			if($menu_expand === true || (is_array($menu_expand) && in_array($menu['id'], $menu_expand))){
				$pic = 'sub';
			}else{
				$pic = 'add';
			}
			$menu_arr[] = '<li class="'.$pic.'"><a href="#" name="'.$menu['id'].'" onclick="return false;">'.$__l[$menu['name']].'</a>';
		}else{
			$menu_arr[] = '<li class="item"><a href="'.$menu['path'].'" target="'.$menu['target'].'">'.$__l[$menu['name']].'</a>';
		}
		if(isset($menu['menus']) && is_array($menu['menus'])){
			if($menu_expand === true || (is_array($menu_expand) && in_array($menu['id'], $menu_expand))){
				$hide = '';
			}else{
				$hide = ' style="display:none;"';
			}
			$menu_arr[] = '<ul'.$hide.'>'.make_menu_ul($menu['menus'], $menu_expand).'</ul></li>';
		}else{
			$menu_arr[] = '</li>';
		}
	}
	$menu_arr[] = '<div class="separate"></div>';
	return implode("\n", $menu_arr);
}
?>